package com.example.blogsystem.service;

import com.example.blogsystem.dao.ArticleMapper;
import com.example.blogsystem.model.Articleinfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: DELL
 * Date: 2023-09-03
 * Time: 23:15
 */

@Service
public class ArticleService {

    @Autowired
    private ArticleMapper articleMapper;

    /**
     * 根据 uid 查询文章
     *
     * @param uid
     * @return
     */
    public List<Articleinfo> getArticleByUid(int uid) {
        return articleMapper.getArticleByUid(uid);
    }

    /**
     * 根据 aid + uid 删除文章
     *
     * @param aid
     * @param uid
     * @return
     */
    public int delByAidAndUid(int aid, int uid) {
        return articleMapper.delByAidAndUid(aid, uid);
    }

    /**
     * 增加博客
     *
     * @param articleinfo
     * @return
     */
    public int add(Articleinfo articleinfo) {
        return articleMapper.add(articleinfo);
    }

    /**
     * 根据 aid 和 uid 查询特定博客
     *
     * @param aid
     * @param uid
     * @return
     */
    public Articleinfo getByAidAndUid(int aid, int uid) {
        return articleMapper.getByAidAndUid(aid, uid);
    }

    /**
     * 更新博客
     *
     * @param articleinfo
     * @return
     */
    public int update(Articleinfo articleinfo) {
        return articleMapper.update(articleinfo);
    }

    /**
     * 根据 aid 查询对应博客信息
     *
     * @param aid
     * @return
     */
    public Articleinfo getByAid(int aid) {
        return articleMapper.getByAid(aid);
    }

    /**
     * 根据 uid 查询其发表文章总数
     *
     * @param uid
     * @return
     */
    public int getCountByUid(int uid) {
        return articleMapper.getCountByUid(uid);
    }

    /**
     * 文章阅读量加 1
     *
     * @param aid
     * @return
     */
    public int readCountIncrement(int aid) {
        return articleMapper.readCountIncrement(aid);
    }

    /**
     * 根据 页码 + 偏移量 查询特定博客
     *
     * @param psize
     * @param offset
     * @return
     */
    public List<Articleinfo> getArtByPage(int psize, int offset) {
        return articleMapper.getArtByPage(psize, offset);
    }

    /**
     * 查询文章总数
     *
     * @return
     */
    public int getAllArtCount() {
        return articleMapper.getAllArtCount();
    }
}
